package cn.tj212.xiaoyin.core.consts.service.impl;

import cn.tj212.xiaoyin.common.page.TailPage;
import cn.tj212.xiaoyin.common.storage.QiniuStorage;
import cn.tj212.xiaoyin.core.consts.dao.ConstsSiteCarouselDao;
import cn.tj212.xiaoyin.core.consts.domain.ConstsSiteCarousel;
import cn.tj212.xiaoyin.core.consts.service.IConstsSiteCarouselService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConstsSiteCarouselServiceImpl implements IConstsSiteCarouselService {

    @Autowired
    private ConstsSiteCarouselDao entityDao;

    @Override
    public ConstsSiteCarousel getById(Long id) {
        return entityDao.getById(id);
    }

    @Override
    public List<ConstsSiteCarousel> queryCarousels(Integer count) {
        List<ConstsSiteCarousel> resultList=entityDao.queryCarousels(count);
        //处理为七牛云连接
        for (ConstsSiteCarousel item:resultList
             ) {
            item.setPicture(QiniuStorage.getUrl(item.getPicture()));
        }
        return resultList;
    }

    @Override
    public TailPage<ConstsSiteCarousel> queryPage(ConstsSiteCarousel queryEntity, TailPage<ConstsSiteCarousel> page) {
        Integer itemsTotalCount=entityDao.getTotalItemsCount(queryEntity);
        List<ConstsSiteCarousel> items=entityDao.queryPage(queryEntity,page);
        if (CollectionUtils.isNotEmpty(items)){
            for (ConstsSiteCarousel item:items
                 ) {
                String pictureUrl=QiniuStorage.getUrl(item.getPicture());
                item.setPicture(pictureUrl);
            }
        }
        page.setItemsTotalCount(itemsTotalCount);
        page.setItems(items);
        return page;
    }

    @Override
    public void create(ConstsSiteCarousel entity) {
        entityDao.create(entity);
    }

    @Override
    public void createSelectivity(ConstsSiteCarousel entity) {
        this.entityDao.createSelectivity(entity);
    }

    @Override
    public void update(ConstsSiteCarousel entity) {
        entityDao.update(entity);
    }

    @Override
    public void updateSelectivity(ConstsSiteCarousel entity) {
        entityDao.updateSelectivity(entity);
    }

    @Override
    public void delete(ConstsSiteCarousel entity) {
        entityDao.delete(entity);
    }

    @Override
    public void deleteLogic(ConstsSiteCarousel entity) {
        entityDao.deleteLogic(entity);
    }
}
